#include <iostream>
#include <cstring>
using namespace std;

void multi(int *a, int *b, int len_a, int len_b)
{
    bool is_empty = true;
    for (int i = 0; i < len_a; i++)
    {
        for (int j = 0; j < len_b; j++)
        {
            if (a[i] == b[j])
            {
                cout << a[i] << ' ';
                is_empty = false;
            }
        }
    }
    if (!is_empty)
    {
        cout << endl;
    }
}

// 求两个集合的并集
void union_set(int *a, int *b, int len_a, int len_b)
{
    bool is_empty = true;
    int *ptr_a, *ptr_b;
    ptr_a = a;
    ptr_b = b;
    while (ptr_a < a + len_a && ptr_b < b + len_b)
    {
        if (*ptr_a != *(ptr_a - 1) || *ptr_b != *(ptr_b - 1))
        {
            if (*ptr_a < *ptr_b)
            {
                cout << *ptr_a << ' ';
                is_empty = false;
                ptr_a++;
            }
            else if (*ptr_a > *ptr_b)
            {
                cout << *ptr_b << ' ';
                is_empty = false;
                ptr_b++;
            }
            else
            {
                cout << *ptr_a << ' ';
                is_empty = false;
                ptr_a++;
                ptr_b++;
            }
        }
    }
    while (ptr_a < a + len_a)
    {
        if (*ptr_a != *(ptr_a - 1))
        {
            cout << *ptr_a << ' ';
            is_empty = false;
        }
        ptr_a++;
    }
    while (ptr_b < b + len_b)
    {
        if (*ptr_b != *(ptr_b - 1))
        {
            cout << *ptr_b << ' ';
            is_empty = false;
        }
        ptr_b++;
    }
    if (!is_empty)
    {
        cout << endl;
    }
}
// 求两个集合的余集
void complement(int *a, int *b, int len_a, int len_b)
{
    for (int i = 0; i < len_a; i++)
    {
        bool flag = false;
        for (int j = 0; j < len_b; j++)
        {
            if (a[i] == b[j])
            {
                flag = true;
                break;
            }
        }
        if (!flag)
        {
            cout << a[i] << ' ';
        }
    }
}

int main()
{
    int num_a, num_b;
    cin >> num_a;
    int *a = new int[num_a];
    for (int i = 0; i < num_a; i++)
    {
        cin >> a[i];
    }
    cin >> num_b;
    int *b = new int[num_b];
    for (int i = 0; i < num_b; i++)
    {
        cin >> b[i];
    }

    multi(a, b, num_a, num_b);
    union_set(a, b, num_a, num_b);
    complement(a, b, num_a, num_b);

    delete[] a;
    delete[] b;

    return 0;
}